import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'

const routes: Array<RouteRecordRaw> = [
  {
    path: '/login',
    name: 'Login',
    component: () => import('../views/login.vue')
  },
  {
    path: '/reg',
    name: 'Reg',
    component: () => import('../views/reg.vue')
  },
  {
    path: '/',
    name: 'Home',
    component: () => import('../views/home.vue'),
    redirect: '/user1',
    children: [
      {
        path: "/user1",
        name: "User1",
        components: {
          default: () => import('../views/A.vue'),
        }
      },
      {
        path: "/user2",
        name: "User2",
        components: {
          bbb: () => import('../views/B.vue'),
          ccc: () => import('../views/C.vue'),
        }
      }
    ]
  },
]

const router = createRouter({
  history: createWebHistory(),
  scrollBehavior: (to, from, savedPosition) => {
    // 保持上次滚动位置
    if (savedPosition) {
      return savedPosition
    } else {
      return { top: 0 }
    }
  },
  routes
})

export default router